package com.boat.starter.jetcache.service;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

import com.alicp.jetcache.anno.support.SpringConfigProvider;

import cn.hutool.core.lang.Assert;
import lombok.extern.slf4j.Slf4j;

/**
 * jetcache上下文类
 * 
 * @author 周江
 *
 */
@Slf4j
public class JetcacheContext implements ApplicationContextAware {
	private static ApplicationContext springContext;
	private static SpringConfigProvider springConfigProvider;

	public static ApplicationContext getSpringContext() {
		Assert.notNull(springContext, "Jetcache未正确初始化");
		return springContext;
	}

	public static SpringConfigProvider getSpringConfigProvider() {
		Assert.notNull(springConfigProvider, "Jetcache未正确初始化");
		return springConfigProvider;
	}

	@Override
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		JetcacheContext.springContext = applicationContext;
		JetcacheContext.springConfigProvider = applicationContext.getBean(SpringConfigProvider.class);
	}
}
